package com.example.ui.service.ribbon;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * 使用ribbon调用producer服务
 *
 * @author 86188
 */
@Service
public class ConsumerHystrixService {

    @Autowired
    private RestTemplate restTemplate;

     @HystrixCommand(fallbackMethod = "fallbackMessage")//当该方法调用失败时,调用 fallbackMessage 方法
    public String getMessage() {
        return restTemplate.getForObject("http://consumer/getMessage", String.class);
    }

    public String fallbackMessage() {
        return "consumer service 模块故障";
    }

}
